package cn.anquing.demo.elasticsearch.demo.jpa;

import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;

/**
 * @author wangqq65
 * @since 2021/4/20 18:05
 */
@Service
public class BlogService {

    @Resource
    private BlogRepository blogRepository;

    public List<Blog> searchByKeyword(String keyword){
        return blogRepository.search(keyword);
    }

    public Blog getById(Long id){
        Optional<Blog> optional = blogRepository.findById(id);
        if (optional.isPresent()){
            return optional.get();
        }
        return new Blog();
    }

}
